/**
 * 
 */
package com.li.service.impl;

import java.io.InputStream;
import java.util.Map;

import com.li.message.req.ReqBaseMessage;
import com.li.service.CoreService;
import com.li.service.ManagerReqMsg;
import com.li.service.RespMsgService;
import com.li.utils.MessageUtil;

/**
 * 核心服务类
 * @author liandyao
 * @date 2016年1月23日
 *
 */
public class CoreServiceImpl implements CoreService{
	
	public InputStream is ;
	
	private ReqBaseMessage reqBaseMessage ;
	
	/**
	 * 得到封装的reqBaseMessage
	 * @return
	 */
	public ReqBaseMessage getReqBaseMessage() {
		return reqBaseMessage;
	}
 
	 
	/**
	 * 封装接收的消息map
	 */
	private Map<String, String> requestMap ;
	 
	/**
	 * 处理响应消息的接口
	 */
	private RespMsgService respMsgService ;
	
	public CoreServiceImpl(InputStream is,RespMsgService respMsgService) {
		this.is = is ;
		this.respMsgService = respMsgService ;
	}
	
	

	@Override
	public String processRequest() {
		
		//将请求的信息进行封装
		reqBaseMessage = ManagerReqMsg.getBaseMessage(getRequestMap()) ;
		//调用处理响应的消息
		String xml = respMsgService.respMsg(reqBaseMessage) ;
		return xml ;
	}  
	
	public Map<String, String> getRequestMap() {
		
		if(this.requestMap!=null) return this.requestMap ;
		
		Map<String, String> reqMap = null ;
		try {
			reqMap = MessageUtil.parseXml(is);
		} catch (Exception e) { 
			e.printStackTrace();
		} 
		this.requestMap = reqMap ;
		return reqMap ;
	}

 
	
	public RespMsgService getRespMsgService() {
		return respMsgService;
	}

	public void setRespMsgService(RespMsgService respMsgService) {
		this.respMsgService = respMsgService;
	}
}
